﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;

namespace Player
{
    public class SearchingProgressUpdatedEventArgs : EventArgs
    {
        public SearchingProgressUpdatedEventArgs(long timeStamp)
        {
            TimeStamp = timeStamp;
        }

        public long TimeStamp { get; protected set; }
    }

    public class SearchThread : WorkerThread<SearchingProgressUpdatedEventArgs>
    {
        private SessionBase m_session;

        public SearchThread(SessionBase session)
        {
            m_session = session;
        }

        protected override void Run(params object[] args)
        {
            // Fast forward to the start time
            long timeStamp = (long)args[0];
            string[] searchWords = (string[])args[1];
            foreach (var frame in m_session.SearchFrames(timeStamp, searchWords))
            {
                SyncUpdate(new SearchingProgressUpdatedEventArgs(frame.TimeStamp));
                Thread.Sleep(0);
                if (ShouldStop) return;
                //only return one search result
                break;
            }
        }
    }
}
